package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.PastDealHandler;
import com.cungmua.app.model.request.CancelOrderRequest;
import com.cungmua.app.model.response.CancelOrderResponse;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/25/14.
 */
public class CancelOrderTask extends AuthenticatedTask<CancelOrderRequest, Void, CancelOrderResponse> {
    private Context context;
    private PastDealHandler handler;

    public CancelOrderTask(Context context, PastDealHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected CancelOrderResponse doInBackground() throws RetrofitError {
        CancelOrderRequest request = params[0];
        return service.cancelOrder(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(CancelOrderResponse cancelOrderResponse) {
        handler.onCancelSuccess(cancelOrderResponse);
    }
}
